package com.itheima.other;

import com.itheima.RabbitUtils;
import com.rabbitmq.client.*;

import java.io.IOException;

/**
 * @作者 itcast
 * @创建日期 2020/11/4 11:36
 **/
public class ColorConsumer {
    private static final String RED_QUEUE = "red_queue";
    private static final String GREEN_QUEUE = "green_queue";
    private static final String YELLOW_QUEUE = "yellow_queue";
    private static final String COLOR_QUEUE = "color_queue";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitUtils.getChannel();
        Consumer consumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println(consumerTag + "处理了消息: " + new String(body));
            }
        };
        channel.basicConsume(COLOR_QUEUE,true,COLOR_QUEUE,consumer);
    }
}
